package be.android.forap.javacard;

public class Commands {
	
	public final static byte[] selectAID_APDU = {
		(byte) 0xD2, 0x13, 0x00, 0x01, 0x16, 0x00, 0x04,
		(byte) 0xFF, 0x49, 0x50, 0x25, (byte) 0x89,
		(byte) 0xC0, 0x01, (byte) 0x9B, 0x01 };
	
	
	public final static byte CLA =	(byte) 0x90;
	public final static byte INS_IMPORT = 0x20;
	public final static byte P1_IMPORT_DATA_REMAINING = 0x00;
	public final static byte P1_IMPORT_DATA_END = 0x11;
	
	
	/*public final  byte[] helloCommand = {CLA, 0x10, 0x00, 0x00, 0x00 };
	public final  byte[] importData_remaining = {CLA, 0x20, 0x00, 0x00};
	public final  byte[] importData_lastdata = {CLA, 0x20, 0x11, 0x00};*/
	public final static byte[] exportData = {CLA, 0x21, 0x00, 0x00};
	
	public final static byte[] setPublicKey = {CLA, 0x30, 0x00, 0x00};
	public final static byte[] setPrivateKeyExp = {CLA, 0x31, 0x00, 0x00};
	public final static byte[] setPrivateKeyMod = {CLA, 0x32, 0x00, 0x00};
	
	public final static byte[] encryptSessionData = {CLA, 0x40, 0x00, 0x00};
	public final static byte[] decryptSessionData = {CLA, 0x41, 0x00, 0x00};
	
	public final static byte[] generateSessionKey = {CLA, 0x50, 0x00, 0x00};
	
	public final static byte[] initDataEncryption = {CLA, 0x60, 0x00, 0x00};
	public final static byte INS_UPDATE_DATA_ENCRYPTION =  0x61;
	public final static byte[] finalizeDataEncryption = {CLA, 0x62, 0x00, 0x00};
	
	public final static byte[] ptBuffer = {CLA, 0x26, 0x00, 0x00};
	
	public static byte[] getImportDataApdu(byte[] tail, boolean data_remaining){
		byte P1;
		if(data_remaining){
			P1 = P1_IMPORT_DATA_REMAINING;
		}else{
			P1=P1_IMPORT_DATA_END;
		}	
		byte[] head = new byte[] {CLA, INS_IMPORT, P1, 0x00, (byte)tail.length };
		// upload apdu
		byte[] apdu = new byte[head.length + tail.length];
		System.arraycopy(head, 0, apdu, 0, head.length);
		System.arraycopy(tail, 0, apdu, head.length, tail.length);		
		return apdu;		
	}
	
	
	public static byte[] getUpdateEncryptDataApdu(byte[] tail){
		byte[] head = new byte[] {CLA, INS_UPDATE_DATA_ENCRYPTION, 0x00, 0x00, (byte)tail.length };
		// upload apdu
		byte[] apdu = new byte[head.length + tail.length];
		System.arraycopy(head, 0, apdu, 0, head.length);
		System.arraycopy(tail, 0, apdu, head.length, tail.length);		
		return apdu;		
	}
}
